﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace TextAnalyzer
{
    /// <summary>
    /// DataGridDialog.xaml에 대한 상호 작용 논리
    /// </summary>
    public partial class ConfigurationDialog : Window
    {
        private TextViewModel mViewModel = null;
        public ConfigurationDialog()
        {
            InitializeComponent();

            try
            {
                if (null == mViewModel) mViewModel = TextViewModel.GetInstance();
                DataContext = mViewModel;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "오류");
            }
        }

        private void OnClickButtonAddPostfix(object sender, RoutedEventArgs e)
        {
            if (null == mViewModel.PostfixParent) MessageBox.Show("조건을 지정할 검색 방법을 선택하십시오.");
            else mViewModel.Postfix.Add(new PostfixViewModel(null,false,mViewModel.PostfixParent.Key));
        }

        private void OnClickButtonDeletePostfix(object sender, RoutedEventArgs e)
        {
            PostfixViewModel _selected = listBoxPostfix.SelectedItem as PostfixViewModel;
            if (null != _selected) mViewModel.Postfix.Remove(_selected);
        }

        private void OnClickButtonAddCategory(object sender, RoutedEventArgs e)
        {
            if (null == mViewModel.CategoryParent) MessageBox.Show("조건을 지정할 검색 방법을 선택하십시오.");
            else mViewModel.Categories.Add(new CategoryViewModel(null, false, mViewModel.CategoryParent.Key));
        }

        private void OnClickButtonDeleteCategory(object sender, RoutedEventArgs e)
        {
            CategoryViewModel _selected = listBoxCategory.SelectedItem as CategoryViewModel;
            if (null != _selected) mViewModel.Categories.Remove(_selected);
        }
    }
}
